<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once "class/Load.class.php";
require_once "class/WowTable.class.php";
require_once "class/Inputs.class.php";
require_once "class/Config.class.php";
require_once "class/CharacterManager.class.php";
require_once "class/CharacterDisplayer.class.php";
require_once "class/CharacterSortMethodContainer.class.php";
require_once "class/StatusRoster.class.php";
require_once "class/Localization.class.php";

$load = Load::GetInstance();
$config = Config::GetInstance();
$inputs = Inputs::GetInstance();
$character_manager = CharacterManager::GetInstance();
$character_displayer = CharacterDisplayer::GetInstance();
$character_sort_method_container = CharacterSortMethodContainer::GetInstance();
$localization = Localization::GetInstance();
$status_roster = StatusRoster::GetInstance();

$wow_table = new WowTable( $localization->Get('characters of the %s guild(s)', implode(", ", $config->GetRosterGuilds()) ) );
$wow_table->AddColumn( $localization->Get('name') );
$wow_table->AddColumn( $localization->Get('class'), "center", 45 );
$wow_table->AddColumn( $localization->Get('links'), "center", 80 );
$wow_table->AddColumn( $localization->Get('level'), "center" );
$wow_table->AddColumn( $localization->Get('experience'), null, 106 );
$wow_table->AddColumn( $localization->Get('title'), "center" );
$wow_table->AddColumn( $localization->Get('played time'), "center" );
$wow_table->AddColumn( $localization->Get('revision'), "center" );
$wow_table->AddColumn( $localization->Get('last update'), "center" );

foreach ($character_manager->GetAllCharacters( $character_sort_method_container->GetSortMethodOrDefault($inputs->Get('sort')) ) as $subsection_name => $character_or_section)
{
	if ( is_array($character_or_section) )
	{
		if ( $wow_table->HasSubsection($subsection_name) == false )
		{
			$wow_table->AddSubsection($subsection_name);
		}
		
		foreach ($character_or_section as $character)
		{
			$wow_table->AddLine($subsection_name, array(
				$character_displayer->Name($character),
				$character_displayer->Class_($character),
				$character_displayer->Links($character),
				$character_displayer->Level($character),
				$character_displayer->Experience($character),
				$character_displayer->GuildTitle($character),
				$character_displayer->TimePlayed($character),
				$character_displayer->Revision($character),
				$character_displayer->LastUpdate($character),
			));
		}
	}
	else
	{
		if ( $wow_table->HasSubsection(0) == false )
		{
			$wow_table->AddSubsection();
		}
		
		$wow_table->AddLine(0, array(
			$character_displayer->Name($character_or_section),
			$character_displayer->Class_($character_or_section),
			$character_displayer->Links($character_or_section),
			$character_displayer->Level($character_or_section),
			$character_displayer->Experience($character_or_section),
			$character_displayer->GuildTitle($character_or_section),
			$character_displayer->TimePlayed($character_or_section),
			$character_displayer->Revision($character_or_section),
			$character_displayer->LastUpdate($character_or_section),
		));
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
	<head>
		<title>LZRoster<?php echo $config->HasRosterTitle() ?  " - ".$config->GetRosterTitle() : null; ?></title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/_.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/characters.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/wowtable.css" />
		<script type="text/javascript" src="js/overlib.js"><!-- overLIB (c) Erik Bosrup --></script>
		<script type="text/javascript" src="js/display.js"></script>
	</head>
	<body>
		
		<?php require_once "inc/head.php"; ?>
		<?php require_once "inc/hmenu.php"; ?>
		
		<p id="charactermenu">
			
			<?php echo $localization->Get('sort'); ?>
			
			<?php
			foreach ($character_sort_method_container->GetAvailableSortMethods() as $character_sort_method)
			{
			?>
			
			<img src="img/<?php echo $character_sort_method->GetSmallIcon(); ?>" alt="" />
			<a href="?sort=<?php echo $character_sort_method->GetId(); ?>"><?php echo $character_sort_method->GetName(); ?></a>
			
			<?php
			}
			?>
			
		</p>
		
		<h2>
			<img src="img/<?php echo $character_sort_method_container->GetSortMethodOrDefault($inputs->Get('sort'))->GetBigIcon(); ?>" alt="" style="vertical-align: middle;" />
			<?php echo $localization->Get('characters'); ?>
			(<?php echo $character_sort_method_container->GetSortMethodOrDefault($inputs->Get('sort'))->GetName(); ?>)	
		</h2>
		
		<?php
		if ($status_roster->HasMessage())
		{
		?>
			
			<p>
				<?php echo $localization->Get('this page produced some messages. please refer to the following lines'); ?>
			</p>
			
			<?php echo $status_roster->GetStack_InList(); ?>
			
			<p>
				<?php echo $localization->Get('you can refresh the page %s and try again', "characters.php"); ?>
			</p>
			
		<?php
		}
		else
		{
		?>
		
		<?php $wow_table->GetAndPrintTable(true); ?>
		
		<?php
		}
		?>
		
		<?php require_once "inc/foot.php"; ?>
		
	</body>
</html>